const HTTP = require('../../models/http');

Page({
  data: {
    items: ["个性推荐", "歌单", "主播电台", "排行榜"],
    currentIndex: 0,
    banners: "",
    hotSongs:"",
    newSongs:"",
    djSongs:"",
    indicatorDots: true,
    autoplay: false,
    interval: 5000,
    duration: 1000
  },
  handleItem(event) {
    var index = event.currentTarget.dataset.index;
    this.setData({
      currentIndex: index
    })
  },
  onLoad: async function () {
    var {banners} = await HTTP.getBanner();
    var hotSongs = await HTTP.getHotSongs();
    var newSongs = await HTTP.getJapanSongs();
    var djSongs = await HTTP.getRecommendDj();
    var songs=[]
    djSongs.result.forEach(item=>{
      var obj = {}
      obj.id = item.id;
      obj.name = item.name;
      obj.coverImgUrl = item.picUrl;
      obj.playCount = item.program.adjustedPlayCount;
      songs.push(obj)
    })
    this.setData({
      hotSongs:hotSongs.playlists.slice(0,3),
      banners,
      newSongs:newSongs.playlists.slice(0,3),
      djSongs:songs.slice(0,3)
    })
  }
})